package com.twu.biblioteca.library.controllers;
import com.twu.biblioteca.Persistence.BooksRepository;
import com.twu.biblioteca.Persistence.ItemsRepository;
import com.twu.biblioteca.library.items.*;

/**
 * Created by S ARUNA on 23-04-2014.
 */
/*Class AvailableBookManager contains Books that are available and operations related to them */
public class BookReservationManager {

    private static final BooksRepository Repository =new BooksRepository();
    public BooksRepository getBooksRepository() { return Repository; }

    //Handles User stories 6,7,8
    public static String checkOut(String ISBN) {
        String success_message="Thank you! Enjoy the book";
        String failure_message="That book is not available";
        ItemsRepository<Book> repository= Repository.getBookSet();
        if(repository.isValidItem(ISBN))
        {
            Book book=(Book)repository.getItemByID(ISBN);
            if(!book.isItemcheckedOut()) {
                book.checkOutItem();
                book.setIscheckedOut(true);
                return success_message;
            }

        }
            return failure_message;

 }
    //Handles User Stories 9,10,11
    public static String returnbook(String ISBN)
    {
        String bookReturn_response="";
        ItemsRepository<Book> repository= Repository.getBookSet();
        if( repository.isItemAvailable(ISBN) || (!(repository.isValidItem(ISBN))))
          bookReturn_response="That is not a valid book to return";
       else
        {
            repository.getItemByID(ISBN).returnItem();
            bookReturn_response="Thank you for returning the book";
        }

        return bookReturn_response;
    }
}

